﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AlexandriaPressAuthorBusinessLayer;
using AlexandriaPressAuthorObject;

namespace AlexandriaPressWebsite.MasterPages.AuthorPages
{
    public partial class SearchAllDrafts : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BusinessAuthor bus = new BusinessAuthor();
            if (!Page.IsPostBack)
            {
                if (HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    if (bus.validateUserIfAuthor(bus.getAuthorID(HttpContext.Current.User.Identity.Name)))
                    {

                    }
                    else
                    {
                        Response.Redirect("~/MasterPages/UserPages/LoggedInUserPage.aspx");
                    }

                }
                else
                {
                    Response.Redirect("~/MasterPages/MainPage.aspx");
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            GridView1.Visible = true;
            GridView2.Visible = false;
            GridView3.Visible = false;
            BusinessAuthor business = new BusinessAuthor();
            List<Draft> lstOfDraft = business.viewApprovedDrafts(business.getAuthorID(HttpContext.Current.User.Identity.Name));
            GridView1.EmptyDataText = "No drafts.";
            GridView1.DataSource = business.createListOfDraft(lstOfDraft);
            GridView1.DataBind();

        }

        protected void searchGridView1_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            BusinessAuthor business = new BusinessAuthor();
            List<Draft> lstOfDraft = business.viewApprovedDrafts(business.getAuthorID(HttpContext.Current.User.Identity.Name));
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataSource = business.createListOfDraft(lstOfDraft);
            GridView1.DataBind();
        }

        protected void searchGridView2_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            BusinessAuthor business = new BusinessAuthor();
            List<Draft> lstOfDraft = business.viewAllDrafts(business.getAuthorID(HttpContext.Current.User.Identity.Name));
            GridView2.PageIndex = e.NewPageIndex;
            GridView2.DataSource = business.createListOfDraft(lstOfDraft);
            GridView2.DataBind();
        }
        protected void searchGridView3_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            BusinessAuthor bus = new BusinessAuthor();
            List<Draft> lstOfDraft = bus.viewDraftForEditing(bus.getAuthorID(HttpContext.Current.User.Identity.Name));
            GridView3.PageIndex = e.NewPageIndex;
            GridView3.DataSource = bus.createListOfDraft(lstOfDraft);
            GridView3.DataBind();
        }
        protected void butAllDrafts_Click(object sender, EventArgs e)
        {
            GridView1.Visible = false;
            GridView2.Visible = true;
            GridView3.Visible = false;
            BusinessAuthor business = new BusinessAuthor();
            List<Draft> lstOfDraft = business.viewAllDrafts(business.getAuthorID(HttpContext.Current.User.Identity.Name));
            GridView2.EmptyDataText = "No drafts.";
            GridView2.DataSource = business.createListOfDraft(lstOfDraft);
            GridView2.DataBind();
        }

        protected void butDraftToEdit_Click(object sender, EventArgs e)
        {
            GridView1.Visible = false;
            GridView2.Visible = false;
            GridView3.Visible = true;
            BusinessAuthor bus = new BusinessAuthor();
            List<Draft> lstOfDraft = bus.viewDraftForEditing(bus.getAuthorID(HttpContext.Current.User.Identity.Name));
            GridView3.EmptyDataText = "No drafts.";
            GridView3.DataSource = bus.createListOfDraft(lstOfDraft);
            GridView3.DataBind();

        }
    }
}
